<!-- 所有文章表格显示 -->
<h1>Table</h1>
<div id="filter-info"></div>
<div id="items"></div>
<script src="/js/time-fmt.min.js"></script>
<script>
    function notNullList(list, prefix) {
        if (list && list.length > 0) {
            let result = ""
            list.forEach(item => {
                result += `<li><a href="/${prefix}/${item.toLowerCase().replace(" ", '-')}/">${item.toLowerCase()}</a></li>`
            })
            return result;
        } else {
            return ""
        }
    }
    fetch("/filter.json").then(res => res.json()).then(data => {
        document.getElementById("filter-info").innerHTML = data.totalItems + " 项";
        const items = document.getElementById("items");
        let tableIn = "<tr><td>时间</td><td>标题</td><td>分类</td><td>标签</td></tr>";
        data.orderedItems.forEach(item => {
            tableIn += `
            <tr>
                <td>${formatTime(item.published)}</td>
                <td><a href="${item.slug}">${item.title}</a></td>
                <td>${notNullList(item.categories, "categories")}</td>
                <td>${notNullList(item.tags, "tags")}</td>
            </tr>
            `
        })
        items.innerHTML = `
        <div style="overflow-x: auto; overflow-y: auto; ">
            <table>${tableIn}</table>
        </div>`
    })
</script>